package com.remote.common;

import io.netty.channel.ChannelOption;
import io.netty.util.internal.StringUtil;

import java.util.LinkedHashMap;
import java.util.Map;

public abstract class RemoteConfiguration {

    private final Map<ChannelOption, Object> options = new LinkedHashMap();

    public abstract String getHost();

    public abstract int getPort();

    public Map<ChannelOption, Object> getOptions() {
        this.buildOption();
        return options;
    }


    protected abstract void buildOption();


    protected void putOption(ChannelOption<?> channelOption, Object value) {
        if (value != null && !StringUtil.isNullOrEmpty(value.toString())) {
            this.options.put(channelOption, value);
        }
    }

    protected void putOptionBean(ChannelOption<?> channelOption, String className) {
        if (!StringUtil.isNullOrEmpty(className)) {
            try {
                options.put(channelOption, Class.forName(className).newInstance());
            } catch (Exception e) {
                throw new IllegalArgumentException("无效Netty配置" + channelOption.name(), e);
            }
        }
    }


}
